﻿using System.IO;
using UnityEditor;
using UnityEngine;

namespace HKTools
{
    /// <summary>
    /// TaskList文件生成
    /// </summary>
    public class HK_CreateTaskList
    {
        [MenuItem("HKTools/HK_TaskSystem/CreateNewTaskList", priority = HK_MenuPriority.HK_CreateTaskList)]
        public static void CreateTaskDatabase()
        {
            HK_TaskList taskList = ScriptableObject.CreateInstance<HK_TaskList>();

            int index = 1;

            while (true)
            {
                string path;

                if (Directory.Exists("Assets/HKTools/ForRuntime/6.HK_TaskSystem/Resources/"))
                {
                    path = string.Format("Assets/HKTools/ForRuntime/6.HK_TaskSystem/Resources/任务链{0}.asset", index.ToString());
                }
                else
                {
                    path = string.Format("Assets/Resources/任务链{0}.asset", index.ToString());
                }

                if (File.Exists(path))
                {
                    index++;
                }
                else
                {
                    AssetDatabase.CreateAsset(taskList, path);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    break;
                }
            }
        }
    }
}